<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GtkDrawingArea</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="GTK+ 2 Reference Manual">
<link rel="up" href="MiscObjects.html" title="Miscellaneous">
<link rel="prev" href="GtkCalendar.html" title="GtkCalendar">
<link rel="next" href="GtkEventBox.html" title="GtkEventBox">
<meta name="generator" content="GTK-Doc V1.18 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="GtkCalendar.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="MiscObjects.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GTK+ 2 Reference Manual</th>
<td><a accesskey="n" href="GtkEventBox.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#GtkDrawingArea.synopsis" class="shortcut">Top</a>
                   | 
                  <a href="#GtkDrawingArea.description" class="shortcut">Description</a>
                   | 
                  <a href="#GtkDrawingArea.object-hierarchy" class="shortcut">Object Hierarchy</a>
                   | 
                  <a href="#GtkDrawingArea.implemented-interfaces" class="shortcut">Implemented Interfaces</a>
</td></tr>
</table>
<div class="refentry">
<a name="GtkDrawingArea"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="GtkDrawingArea.top_of_page"></a>GtkDrawingArea</span></h2>
<p>GtkDrawingArea — A widget for custom user interface elements</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="GtkDrawingArea.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include &lt;gtk/gtk.h&gt;

struct              <a class="link" href="GtkDrawingArea.html#GtkDrawingArea-struct" title="struct GtkDrawingArea">GtkDrawingArea</a>;
<a class="link" href="GtkWidget.html" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a> *         <a class="link" href="GtkDrawingArea.html#gtk-drawing-area-new" title="gtk_drawing_area_new ()">gtk_drawing_area_new</a>                (<em class="parameter"><code><span class="type">void</span></code></em>);
<span class="returnvalue">void</span>                <a class="link" href="GtkDrawingArea.html#gtk-drawing-area-size" title="gtk_drawing_area_size ()">gtk_drawing_area_size</a>               (<em class="parameter"><code><a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> *darea</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gint"><span class="type">gint</span></a> width</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gint"><span class="type">gint</span></a> height</code></em>);
</pre>
</div>
<div class="refsect1">
<a name="GtkDrawingArea.object-hierarchy"></a><h2>Object Hierarchy</h2>
<pre class="synopsis">
  <a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#GObject">GObject</a>
   +----<a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#GInitiallyUnowned">GInitiallyUnowned</a>
         +----<a class="link" href="GtkObject.html" title="GtkObject">GtkObject</a>
               +----<a class="link" href="GtkWidget.html" title="GtkWidget">GtkWidget</a>
                     +----GtkDrawingArea
                           +----<a class="link" href="GtkCurve.html" title="GtkCurve">GtkCurve</a>
                           +----<a class="link" href="GtkSpinner.html" title="GtkSpinner">GtkSpinner</a>
</pre>
</div>
<div class="refsect1">
<a name="GtkDrawingArea.implemented-interfaces"></a><h2>Implemented Interfaces</h2>
<p>
GtkDrawingArea implements
 AtkImplementorIface and  <a class="link" href="GtkBuildable.html" title="GtkBuildable">GtkBuildable</a>.</p>
</div>
<div class="refsect1">
<a name="GtkDrawingArea.description"></a><h2>Description</h2>
<p>
The <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> widget is used for creating custom user interface
elements. It's essentially a blank widget; you can draw on
<code class="literal">widget-&gt;window</code>. After creating a drawing area,
the application may want to connect to:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
    Mouse and button press signals to respond to input from
    the user. (Use <a class="link" href="GtkWidget.html#gtk-widget-add-events" title="gtk_widget_add_events ()"><code class="function">gtk_widget_add_events()</code></a> to enable events
    you wish to receive.)
    </p></li>
<li class="listitem"><p>
    The "realize" signal to take any necessary actions
    when the widget is instantiated on a particular display.
    (Create GDK resources in response to this signal.)
    </p></li>
<li class="listitem"><p>
    The "configure_event" signal to take any necessary actions
    when the widget changes size.
    </p></li>
<li class="listitem"><p>
    The "expose_event" signal to handle redrawing the
    contents of the widget.
    </p></li>
</ul></div>
<p>
</p>
<p>
The following code portion demonstrates using a drawing
area to display a circle in the normal widget foreground
color.
Note that GDK automatically clears the exposed area
to the background color before sending the expose event, and
that drawing is implicitly clipped to the exposed area.
</p>
<div class="example">
<a name="id1148067"></a><p class="title"><b>Example 53. Simple <span class="structname">GtkDrawingArea</span> usage.</b></p>
<div class="example-contents">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="normal"><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gboolean">gboolean</a></span>
<span class="function">expose_event_callback</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GtkWidget</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">widget</span><span class="symbol">,</span><span class="normal"> </span><span class="usertype">GdkEventExpose</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">event</span><span class="symbol">,</span><span class="normal"> </span><span class="usertype">gpointer</span><span class="normal"> data</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="function"><a href="../gdk/gdk-Drawing-Primitives.html#gdk-draw-arc">gdk_draw_arc</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">widget</span><span class="symbol">-&gt;</span><span class="normal">window</span><span class="symbol">,</span>
<span class="normal">                widget</span><span class="symbol">-&gt;</span><span class="normal">style</span><span class="symbol">-&gt;</span><span class="normal">fg_gc</span><span class="symbol">[</span><span class="function"><a href="GtkWidget.html#gtk-widget-get-state">gtk_widget_get_state</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">widget</span><span class="symbol">)],</span>
<span class="normal">                <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">,</span>
<span class="normal">                </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> widget</span><span class="symbol">-&gt;</span><span class="normal">allocation</span><span class="symbol">.</span><span class="normal">width</span><span class="symbol">,</span><span class="normal"> widget</span><span class="symbol">-&gt;</span><span class="normal">allocation</span><span class="symbol">.</span><span class="normal">height</span><span class="symbol">,</span>
<span class="normal">                </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">64</span><span class="normal"> </span><span class="symbol">*</span><span class="normal"> </span><span class="number">360</span><span class="symbol">);</span>
<span class="normal">  </span><span class="keyword">return</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">;</span>
<span class="cbracket">}</span>
<span class="symbol">[...]</span>
<span class="normal">  </span><span class="usertype">GtkWidget</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">drawing_area </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GtkDrawingArea.html#gtk-drawing-area-new">gtk_drawing_area_new</a></span><span class="normal"> </span><span class="symbol">();</span>
<span class="normal">  </span><span class="function"><a href="GtkWidget.html#gtk-widget-set-size-request">gtk_widget_set_size_request</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">drawing_area</span><span class="symbol">,</span><span class="normal"> </span><span class="number">100</span><span class="symbol">,</span><span class="normal"> </span><span class="number">100</span><span class="symbol">);</span>
<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Signals.html#g-signal-connect">g_signal_connect</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT:CAPS">G_OBJECT</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">drawing_area</span><span class="symbol">),</span><span class="normal"> </span><span class="string">"expose_event"</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="function"><a href="http://library.gnome.org/devel/gobject/unstable/gobject-Closures.html#G-CALLBACK:CAPS">G_CALLBACK</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">expose_event_callback</span><span class="symbol">),</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
<br class="example-break"><p>
Expose events are normally delivered when a drawing area first comes
onscreen, or when it's covered by another window and then uncovered
(exposed). You can also force an expose event by adding to the "damage
region" of the drawing area's window; <a class="link" href="GtkWidget.html#gtk-widget-queue-draw-area" title="gtk_widget_queue_draw_area ()"><code class="function">gtk_widget_queue_draw_area()</code></a> and
<a href="../gdk/gdk-Windows.html#gdk-window-invalidate-rect"><code class="function">gdk_window_invalidate_rect()</code></a> are equally good ways to do this. You'll
then get an expose event for the invalid region.
</p>
<p>
The available routines for drawing are documented on the <a href="../gdk/gdk-Drawing-Primitives.html">GDK Drawing Primitives</a> page.
See also <a href="../gdk/gdk-Drawing-Primitives.html#gdk-draw-pixbuf"><code class="function">gdk_draw_pixbuf()</code></a> for drawing a <a href="http://library.gnome.org/devel/gdk-pixbuf/unstable/gdk-pixbuf-The-GdkPixbuf-Structure.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a>.
</p>
<p>
To receive mouse events on a drawing area, you will need to enable
them with <a class="link" href="GtkWidget.html#gtk-widget-add-events" title="gtk_widget_add_events ()"><code class="function">gtk_widget_add_events()</code></a>. To receive keyboard events, you
will need to set the <a class="link" href="GtkWidget.html#GTK-CAN-FOCUS:CAPS"><span class="type">GTK_CAN_FOCUS</span></a> flag on the drawing area, and
should probably draw some user-visible indication that the drawing
area is focused. Use the <a class="link" href="GtkWidget.html#GTK-HAS-FOCUS:CAPS"><code class="function">GTK_HAS_FOCUS()</code></a> macro in your expose event
handler to decide whether to draw the focus indicator. See
<a class="link" href="GtkStyle.html#gtk-paint-focus" title="gtk_paint_focus ()"><code class="function">gtk_paint_focus()</code></a> for one way to draw focus.
</p>
</div>
<div class="refsect1">
<a name="GtkDrawingArea.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="GtkDrawingArea-struct"></a><h3>struct GtkDrawingArea</h3>
<pre class="programlisting">struct GtkDrawingArea;</pre>
<p>
The <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> struct contains private data only, and
should be accessed using the functions below.
</p>
</div>
<hr>
<div class="refsect2">
<a name="gtk-drawing-area-new"></a><h3>gtk_drawing_area_new ()</h3>
<pre class="programlisting"><a class="link" href="GtkWidget.html" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a> *         gtk_drawing_area_new                (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>
Creates a new drawing area.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>a new <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a>
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="gtk-drawing-area-size"></a><h3>gtk_drawing_area_size ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                gtk_drawing_area_size               (<em class="parameter"><code><a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> *darea</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gint"><span class="type">gint</span></a> width</code></em>,
                                                         <em class="parameter"><code><a href="http://library.gnome.org/devel/glib/unstable/glib-Basic-Types.html#gint"><span class="type">gint</span></a> height</code></em>);</pre>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Warning</h3>
<p><code class="literal">gtk_drawing_area_size</code> is deprecated and should not be used in newly-written code. Use <a class="link" href="GtkWidget.html#gtk-widget-set-size-request" title="gtk_widget_set_size_request ()"><code class="function">gtk_widget_set_size_request()</code></a> instead.</p>
</div>
<p>
Sets the size that the drawing area will request
in response to a "size_request" signal. The
drawing area may actually be allocated a size
larger than this depending on how it is packed
within the enclosing containers.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>darea</code></em> :</span></p></td>
<td>a <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>width</code></em> :</span></p></td>
<td>the width to request</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>height</code></em> :</span></p></td>
<td>the height to request</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="refsect1">
<a name="GtkDrawingArea.see-also"></a><h2>See Also</h2>
<p>
Sometimes <a class="link" href="GtkImage.html" title="GtkImage"><span class="type">GtkImage</span></a> is a useful alternative to a drawing area.
You can put a <a href="../gdk/gdk-Bitmaps-and-Pixmaps.html#GdkPixmap"><span class="type">GdkPixmap</span></a> in the <a class="link" href="GtkImage.html" title="GtkImage"><span class="type">GtkImage</span></a> and draw to the <a href="../gdk/gdk-Bitmaps-and-Pixmaps.html#GdkPixmap"><span class="type">GdkPixmap</span></a>,
calling <a class="link" href="GtkWidget.html#gtk-widget-queue-draw" title="gtk_widget_queue_draw ()"><code class="function">gtk_widget_queue_draw()</code></a> on the <a class="link" href="GtkImage.html" title="GtkImage"><span class="type">GtkImage</span></a> when you want to
refresh to the screen.
</p>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.18</div>
</body>
</html>